package com.imd.s9.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Repository;

import java.util.Arrays;
@Repository
public class FSmsg {
    public JSONObject getMsg(String content, JSONObject... fields){
        JSONObject data = new JSONObject();
        data.put("config",config());
        data.put("header",header(content));
        data.put("elements",elements(fields));
        System.out.println("-------A91uQHG5TVuSNRjBgPPAAcJsij1SlWUI-------"+data);
        return data;
    }

    public JSONObject config(){
        JSONObject config = new JSONObject();
        config.put("wide_screen_mode",true);
        return config;
    }

    public JSONObject header(String content){
        JSONObject header = new JSONObject();
        JSONObject title = new JSONObject();
        title.put("tag","plain_text");
        title.put("content",content);
        header.put("title",title);
        return header;
    }

    public JSONArray elements(JSONObject... fields){
        JSONObject element = new JSONObject();
        element.put("tag","div");
        element.put("fields",new JSONArray(Arrays.asList(fields)));
        JSONArray elements = new JSONArray();
        elements.add(element);
        return elements;
    }


    public JSONObject field(Boolean bl,String content){
        JSONObject field = new JSONObject();
        field.put("is_short",bl);
        JSONObject text = new JSONObject();
        text.put("tag","lark_md");
        text.put("content",content);
        field.put("text",text);
        return field;
    }
}
